package cn.yuanqiao.web.controller.es;

import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.enums.BusinessType;
import cn.yuanqiao.es.domain.QueryFile;
import cn.yuanqiao.es.service.AppRetrievalService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 小程序目录检索
 *
 * @ProjectName: JZSDAS
 * @Package: cn.yuanqiao.es.controller
 * @ClassName: AppRetrievalController
 * @Author: lenovo
 * @Description: hbWang
 * @Date: 2023/11/8 9:21
 * @Version: 1.0
 */
@RestController
@RequestMapping("/es/retrieval/api")
public class AppRetrievalController {
    @Autowired
    AppRetrievalService retrievalService;


    /**
     * 查询
     *
     * @return
     */
    //  @RequiresPermissions("es:api:search")
    @PostMapping("/search")
    public Map<String, Object> search(@RequestBody() QueryFile query) {
        return retrievalService.searchApp(query);
    }

    /**
     * 查询当前用户门类信息
     *
     * @param
     * @return cn.yuanqiao.common.core.domain.AjaxResult
     * @author hbWang
     * @date 9:51
     */
    @PostMapping("/categoryList")
    public List<Map<String, Object>> categoryList(@RequestParam(value = "menuId", required = false) String menuId) {
        return retrievalService.categoryList(menuId);
    }

    /**
     * 查询展示列
     *
     * @param json
     * @return
     */
    @PostMapping("/field/list")
    public AjaxResult queryFiels(@RequestBody() JSONObject json) {
        return AjaxResult.success(retrievalService.queryFields(json));
    }

    /**
     * 查询文件列表
     *
     * @param json
     * @return
     */
    @PostMapping("/doc/list")
    public Map<String, Object> queryEfile(@RequestBody() JSONObject json) {
        Map<String, Object> map = new HashMap<>();
        map.put("data", retrievalService.queryEfile(json));
        return map;
    }


    @Log(title = "预览", businessType = BusinessType.OTHER)
    @PostMapping("/view")
    public void view(HttpServletRequest request, HttpServletResponse response) throws Exception {
        retrievalService.view(request, response);
    }
}
